package shaw.wifi;

import shaw.wifi.gui.SecureConnectGui;
import some.pkg.R;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

import android.content.SharedPreferences.Editor;


/* This is the Activity associated with the app, it is the main class for the app.
 * The onCreate function is called when the app is run.
 */

@SuppressWarnings("unused")
public class AndroidAuthActivity extends Activity {
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        
		//set the view to the main layout (defined in the res/layout/main.xml file)
		//this file will tell the app what ui elements exist and where they are
        setContentView(R.layout.main);

        //setup the GUI
        SecureConnectGui.setupGui(this);
        
        NetworkSettingsTaskManager.get().setApplicationContext(this);
        
        SharedPreferences sp = Constants._SHAREDPREFS = this.getSharedPreferences(Constants._SHAREDPREFNAME, Context.MODE_PRIVATE);
        if(sp.contains("APPUSERNAME")) {
        	Log.e("AUTH", "Preferences found!");

        	//uncomment to clear the data here
        	//Editor edit = sp.edit(); edit.clear(); edit.commit();
        	
        	Constants._APPUSERNAME = sp.getString("APPUSERNAME", null);
        	Constants._APPPASSWORD = sp.getString("APPPASSWORD", null);
        } else {
        	Log.e("AUTH", "Preferences missing!");
        }
    }
	
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //Handle the back button
        if(keyCode == KeyEvent.KEYCODE_BACK && Constants._FINISHED == true ) {
            Log.e("DONE", "FINISHED....");
        	this.finish();
        	return true;
        }
        else {
            return super.onKeyDown(keyCode, event);
        }
    }
}